﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;

namespace HeartLess.Managers
{
    public static class AssetManager
    {

        private static ContentManager _contentManager;
        private static Dictionary<FONTS, SpriteFont> _spriteFonts;
        private static Dictionary<ANIMATIONS, Texture2D> _animationTextures;
        private static Dictionary<SPRITES, Texture2D> _spriteTextures;
        private static Dictionary<SHADERS, Effect> _shaders;
        private static Dictionary<SOUNDS, SoundEffect> _sounds;

        public enum FONTS
        {
            MAIN_MENU,
            HUD_FONT
        }

        public enum SPRITES
        {
            BLOCK_NORMAL_ICE,
            BLOCK_NORMAL_JUNGLE,
            BLOCK_END,
            MOVING_BACKGROUND_ICE,
            STATIC_BACKGROUND_ICE,
            MOVING_BACKGROUND_JUNGLE,
            STATIC_BACKGROUND_JUNGLE
        }

        public enum ANIMATIONS
        {
            PLAYER_IDLE,
            PLAYER_RUNNING,
            PLAYER_JUMPING,
            PLAYER_SHOCKWAVE,
            
            GREEN_SLIME_WALK,
            GREEN_SLIME_ATTACK,
            GREEN_SLIME_IDLE,
            BLUE_SLIME_WALK,
            BLUE_SLIME_ATTACK,
            BLUE_SLIME_IDLE,
            RED_SLIME_WALK,
            RED_SLIME_ATTACK,
            RED_SLIME_IDLE,
            SOLDIER_WALK,
            SOLDIER_ATTACK,
            SOLDIER_IDLE,

            HEALTH_MODIFIER,
            HEART_RATE_MODIFIER,
            HEART_BEAT_1,
            HEART_BEAT_2
        }

        public enum SHADERS
        {
            SHOCKWAVE
        }

        public enum SOUNDS
        {
            HEART_BEAT
        }

        public static void Load(ContentManager contentManager)
        {
            _contentManager = contentManager;

            LoadFonts();
            LoadSprites();
            LoadAnimations();
            LoadShaders();
            LoadSounds();

            _contentManager = null;
        }

        public static SpriteFont GetSpriteFont(FONTS font)
        {
            return _spriteFonts[font];
        }

        public static Texture2D GetSpriteTexture(SPRITES sprite)
        {
            return _spriteTextures[sprite];
        }

        public static Texture2D GetAnimationTexture(ANIMATIONS animation)
        {
            return _animationTextures[animation];
        }

        public static Effect GetShader(SHADERS shader)
        {
            return _shaders[shader];
        }

        public static SoundEffect GetSound(SOUNDS sound)
        {
            return _sounds[sound];
        }

        private static void LoadFonts()
        {
            _spriteFonts = new Dictionary<FONTS, SpriteFont>();

            SpriteFont fontMainMenu = _contentManager.Load<SpriteFont>("SpriteFonts/MainMenu");
            _spriteFonts.Add(FONTS.MAIN_MENU, fontMainMenu);
            SpriteFont fontHud = _contentManager.Load<SpriteFont>("SpriteFonts/Hud");
            _spriteFonts.Add(FONTS.HUD_FONT, fontHud);
        }

        private static void LoadAnimations()
        {
            _animationTextures = new Dictionary<ANIMATIONS, Texture2D>();

            Texture2D playerIdle = _contentManager.Load<Texture2D>("Animations/Player/idle");
            _animationTextures.Add(ANIMATIONS.PLAYER_IDLE, playerIdle);

            Texture2D playerRunning = _contentManager.Load<Texture2D>("Animations/Player/running");
            _animationTextures.Add(ANIMATIONS.PLAYER_RUNNING, playerRunning);

            Texture2D playerJumping = _contentManager.Load<Texture2D>("Animations/Player/jumping");
            _animationTextures.Add(ANIMATIONS.PLAYER_JUMPING, playerJumping);

            Texture2D playerShockWave = _contentManager.Load<Texture2D>("Animations/Player/shockwave");
            _animationTextures.Add(ANIMATIONS.PLAYER_SHOCKWAVE, playerShockWave);

            Texture2D slimeWalk = _contentManager.Load<Texture2D>("Animations/Slime/walk");
            _animationTextures.Add(ANIMATIONS.GREEN_SLIME_WALK, slimeWalk);
            _animationTextures.Add(ANIMATIONS.GREEN_SLIME_IDLE, slimeWalk);

            Texture2D slimeAttack = _contentManager.Load<Texture2D>("Animations/Slime/attack");
            _animationTextures.Add(ANIMATIONS.GREEN_SLIME_ATTACK, slimeAttack);
            
            Texture2D slimeBlueWalk = _contentManager.Load<Texture2D>("Animations/BlueSlime/walk");
            _animationTextures.Add(ANIMATIONS.BLUE_SLIME_WALK, slimeBlueWalk);
            _animationTextures.Add(ANIMATIONS.BLUE_SLIME_IDLE, slimeBlueWalk);

            Texture2D slimeBlueAttack = _contentManager.Load<Texture2D>("Animations/BlueSlime/attack");
            _animationTextures.Add(ANIMATIONS.BLUE_SLIME_ATTACK, slimeBlueAttack);
            
            Texture2D slimeRedWalk = _contentManager.Load<Texture2D>("Animations/RedSlime/walk");
            _animationTextures.Add(ANIMATIONS.RED_SLIME_WALK, slimeRedWalk);
            _animationTextures.Add(ANIMATIONS.RED_SLIME_IDLE, slimeRedWalk);
            
            Texture2D slimeRedAttack = _contentManager.Load<Texture2D>("Animations/RedSlime/attack");
            _animationTextures.Add(ANIMATIONS.RED_SLIME_ATTACK, slimeRedAttack);

            Texture2D soldierIdle = _contentManager.Load<Texture2D>("Animations/Soldier/idle");
            _animationTextures.Add(ANIMATIONS.SOLDIER_IDLE, soldierIdle);

            Texture2D soldierWalk = _contentManager.Load<Texture2D>("Animations/Soldier/walk");
            _animationTextures.Add(ANIMATIONS.SOLDIER_WALK, soldierWalk);

            Texture2D soldierAttack = _contentManager.Load<Texture2D>("Animations/Soldier/attack");
            _animationTextures.Add(ANIMATIONS.SOLDIER_ATTACK, soldierAttack);

            Texture2D pill = _contentManager.Load<Texture2D>("Animations/HeartRateModifier/pill");
            _animationTextures.Add(ANIMATIONS.HEALTH_MODIFIER, pill);
            _animationTextures.Add(ANIMATIONS.HEART_RATE_MODIFIER, pill);

            Texture2D heartBeat1 = _contentManager.Load<Texture2D>("Animations/Heartbeat/Heartbeat1");
            _animationTextures.Add(ANIMATIONS.HEART_BEAT_1, heartBeat1);

            Texture2D heartBeat2 = _contentManager.Load<Texture2D>("Animations/Heartbeat/Heartbeat2");
            _animationTextures.Add(ANIMATIONS.HEART_BEAT_2, heartBeat2);
        }

        private static void LoadSprites()
        {
            _spriteTextures = new Dictionary<SPRITES, Texture2D>();

            Texture2D iceBlockTexture = _contentManager.Load<Texture2D>("Sprites/blockIce");
            _spriteTextures.Add(SPRITES.BLOCK_NORMAL_ICE, iceBlockTexture);

            Texture2D jungleBlockTexture = _contentManager.Load<Texture2D>("Sprites/blockJungle");
            _spriteTextures.Add(SPRITES.BLOCK_NORMAL_JUNGLE, jungleBlockTexture);

            Texture2D endBlockTexture = _contentManager.Load<Texture2D>("Sprites/blockEnd");
            _spriteTextures.Add(SPRITES.BLOCK_END, endBlockTexture);

            Texture2D movingBackground1Texture = _contentManager.Load<Texture2D>("Sprites/movingBackgrounds/1");
            _spriteTextures.Add(SPRITES.MOVING_BACKGROUND_ICE, movingBackground1Texture);

            Texture2D staticBackground1Texture = _contentManager.Load<Texture2D>("Sprites/staticBackgrounds/1");
            _spriteTextures.Add(SPRITES.STATIC_BACKGROUND_ICE, staticBackground1Texture);
            
            Texture2D movingBackground2Texture = _contentManager.Load<Texture2D>("Sprites/movingBackgrounds/2");
            _spriteTextures.Add(SPRITES.MOVING_BACKGROUND_JUNGLE, movingBackground2Texture);

            Texture2D staticBackground2Texture = _contentManager.Load<Texture2D>("Sprites/staticBackgrounds/2");
            _spriteTextures.Add(SPRITES.STATIC_BACKGROUND_JUNGLE, staticBackground2Texture);
        }

        private static void LoadShaders()
        {
            _shaders = new Dictionary<SHADERS, Effect>();

            Effect shockwave = _contentManager.Load<Effect>("Shaders/Shockwave");
            _shaders.Add(SHADERS.SHOCKWAVE, shockwave);
        }

        private static void LoadSounds()
        {
            _sounds = new Dictionary<SOUNDS, SoundEffect>();

            SoundEffect heartBeat = _contentManager.Load<SoundEffect>("Sounds/HeartBeat");
            _sounds.Add(SOUNDS.HEART_BEAT, heartBeat);
        }
    }
}
